<?php

/**
 * 广州共创接口
 * 短信服务
 * author:censhuixing
 * time:2014-05-27
 */
class youxi
{

	var $config = array('url'=>'http://115.29.194.198/api/http/sendmsg',
	'username'=>'四九游',
	'password'=>'49you123456',//合作者身份ID
	);

	function youxi()
	{

	}


	function return_str($return)
	{
		/*$result = ($return == '1')  ? '发送成功' : '';
		$result = ($return == '-1') ? '账号错误' : $result;
		$result = ($return == '-2') ? '密码错误' : $result;
		$result = ($return == '-3') ? '账号已停用' : $result;
		$result = ($return == '-4') ? '内容或号码为空' : $result;
		$result = ($return == '-5') ? '内容包含非法关键词' : $result;
		$result = ($return == '-6') ? '时间格式错误' : $result;
		$result = ($return == '-7') ? '余额不足' : $result;
		$result = ($return == '-100') ? '无效参数' : $result;
		$result = ($return == '-200') ? '系统错误' : $result;
		$result = empty($result) ? '未知返回' : $result;

		return $result;*/
	}

	/*
	@param $mobile 要发送的手机号码(群发半角逗号,隔开)
	@param $msg 发送内容*/
	function send_sms($msg='',$mobile='')
	{
		$msg = urlencode($msg);
		$fields =array(
		'user'=>$this->config['username'],
		'passwd'=>$this->config['password'],
		'phone'=>$mobile,
		'msg'=>$msg
		);
		$result = $this->post_curl($this->config['url'],$fields);
		if($result >= 1)
		return true;
		else return false;
		
	}


	function post_curl($url, $fields)
	{
		$fields_string ='';
		foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&' ; }
		rtrim($fields_string ,'&');
		$ch = curl_init();
		// 设置 curl 相应属性
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
		$returnTransfer = curl_exec($ch);
		curl_close($ch);
		return $returnTransfer;
	}



	//测试手机
	function send_test_mobile($content='',$mobile='')
	{
		if(empty($content) OR empty($mobile))return;
		$ret = $this->send_sms($content,$mobile);
		//$ret = $this->return_str($ret);
		return $ret;
	}


}





?>